package com.example.second.memo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import com.example.second.R;
import com.example.second.memo.classes.Caretaker;
import com.example.second.memo.classes.Memento;
import com.example.second.memo.classes.Originator;

public class MemoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_memo);
        // 添加数据
        Originator originator = new Originator();
        originator.setMemento(new Memento("liSi", 22));
        originator.show();
        // 创建备忘录
        Caretaker caretaker = new Caretaker();
        caretaker.setMemento(originator.createMemento());
        // 更改数据
        originator.setMemento(new Memento("zhangSan", 23));
        originator.show();
        // 还原数据
        originator.setMemento(caretaker.getMemento());
        originator.show();
    }
}